package leetcode;

/**
 * todo
 *
 * @author zhengshan
 * @Date 2023/3/1 11:22
 */
public class Demo4 {

    private int[] arr;
    private int[] minArr;
    private int size;
    private int min = 0;

    /** initialize your data structure here. */
    public Demo4() {
        this.arr = new int[10];
        this.minArr = new int[10];
    }

    public void push(int x) {
        if(min != 0){
            if(x < minArr[min-1]){
                minArr[min] = x;
                min++;
            }
        }else{
            minArr[min] = x;
            min++;
        }
        arr[size] = x;
        size++;
    }

    public void pop() {
        if(minArr[min-1] == arr[size]){
            --min;
        }
        --size;
    }

    public int top() {
        return arr[size];
    }

    public int min() {
        return minArr[min];
    }

    public static void main(String[] args) {
        Demo4 test = new Demo4();
        test.push(-2);
        test.push(0);
        test.push(-3);
        test.min();
        test.pop();
        test.top();
        test.min();
    }
}
